package com.qlp.start.Task;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author itoutsource.cz10
 * 基于注解的多线程任务
 */
@Component
@EnableScheduling   //开启定时任务
@EnableAsync        //开启多线
public class MultithreadScheduleTask {

    @Async
    @Scheduled(fixedDelay = 1000)  //间隔1秒
    public void first() throws InterruptedException{
         System.out.println("第一个定时任务开始："+ LocalDateTime.now().toLocalTime()+" "+Thread.currentThread().getName());
         Thread.sleep(10000);
    }

    @Async
    @Scheduled(fixedDelay = 2000)
    public void second() throws InterruptedException{
        System.out.println("第二个定时任务开始："+ LocalDateTime.now().toLocalTime()+" "+Thread.currentThread().getName());
    }



}
